const qiniu = require('qiniu')
const Controller = require('egg').Controller


class QiniuUploadController extends Controller {
    async token () {
        const { ctx } = this
        const accessKey = 'oExvyBVv6PQuB5rfLQRhn1Qo_ialLh7mpeamVZng'
        const secretKey = 'Fy8lf0AsO2IuIgm9rLXjaVqJfb3DMglrXJD4peXd'
        const bucket = 'zhihureact'
        const mac = new qiniu.auth.digest.Mac(accessKey,secretKey)

        const putPolicy = new qiniu.rs.PutPolicy({ scope:bucket,expires:3600 * 24 })
        const uploadToken = putPolicy.uploadToken(mac)

        ctx.body = {
            state:'ok',
            qiniuToken:uploadToken
        }
    }
}

module.exports = QiniuUploadController
